#include<opencv4/opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
class ArmorDetector{
    public:
    bool makeRectSafe(cv::Rect & rect, cv::Size size){
        if (rect.x < 0)
            rect.x = 0;
        if (rect.x + rect.width > size.width)
            rect.width = size.width - rect.x;
        if (rect.y < 0)
            rect.y = 0;
        if (rect.y + rect.height > size.height)
            rect.height = size.height - rect.y;
        if (rect.width <= 0 || rect.height <= 0)
            // 如果发现矩形是空的，则返回false
            return false;
        return true;
    }
    void GetArmor();
    RotatedRect finalrect;
    Point2f finalvertex[4];
  
    void Pretreatment();
    void set_mode(int ) ;
    void set_frame(Mat );
    bool find();
    
    private:  
    Mat frame; bool findtarget=0;
    int enemy_color;
    Point diff=Point(0,0);
    Rect _res_last;      // last detect result
    Mat ROIimage;
    int _lost_cnt; 
    cv::Rect _dect_rect;            // detect roi of original image
    Point2f currentCenter;
    vector<RotatedRect> possibleRects;

};
void adjust_rect(RotatedRect& minRect);